<?php
/**
 * 用户
 *
 *
 */


class food_model extends CI_Model
{
	const tableName = "food";
	
	var $name;

	var $unitPrice;
	
	var $isSpicy;

	var $isNew;
	
	var $picture;
	
	var $hasPicture;

	var $categoryId;
	
	var $restaurantId;
	
	var $popularity;	

	function __construct()
	{
		parent::__construct();
	}

	// --------------------------------------------------------------------

	/**
	 *
	 * 插入food数据
	 */
	function insert_food($date)
	{
		$this->name = $date['name'];	
		$this->unitPrice = $date['unitPrice'];		
		$this->isSpicy = $date['isSpicy'];	
		$this->isNew = $date['isNew'];		
		$this->picture = $date['picture'];	
		$this->categoryId = $date['categoryId'];		
		$this->popularity = $date['popularity'];
		
		$this->db->insert(self::tableName, $this);
	}
	
	/**
	 * 
	 * 将饭店的所有菜取出来
	 * @param unknown_type $restaurantid
	 */
	function getFoodByRestaurantid($restaurantid)
	{
		$this->db->where('status', 'ACTIVE');
		$query = $this->db->query("select * from ".self::tableName." where `status`='ACTIVE' and restaurantId = ".$restaurantid);
		return $query->result() ;
	}
	
	/**
	 * load by id
	 *
	 *
	 */
	function load($id)
	{
		if (!$id){
			return array();
		}

		$query = $this->db->get_where(self::tableName,array('id' => $id));

		if ($row = $query->row_array()){
			return $row;
		}

		return array();
	}
}